Skip to main content

跳转 https

session_start();
if(@!$_SERVER['HTTPS']){ // Non – SSL session here
$_SESSION['test'] = 'This was set in the non-SSL part of the session!';
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?PHPSESSID='.session_id());
exit;
}
echo $_SESSION['test']; // Now we are in a secure session

上面的太废了,简单点

if(@!$_SERVER['HTTPS']){ // Non – SSL session here
header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
}

反着写

if(@$_SERVER['HTTPS']){ // Non – SSL session here
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
}